package com.ac.scum.log.web.task;

import com.ac.scum.log.web.model.wechat.pay.mapper.TradeMapper;
import com.ac.scum.pay.Trade;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;


@Slf4j
@Component
@AllArgsConstructor
public class ClearUnPayRecoderTask {
    private final TradeMapper tradeMapper;

    @Scheduled(cron = "0/20 * * * * ?")
    public void clearUnPayRecoder() {
        int delete = tradeMapper.delete(Wrappers.<Trade>lambdaQuery().isNull(Trade::getTradeState).lt(Trade::getCreateTime, LocalDateTime.now().minusHours(4)));
        if (delete > 0) {
            log.info("删除{}条未支付记录", delete);
        }

    }
}
